package cn.da.shuai.cool.system.api.controller;

import cn.da.shuai.cool.common.entity.R;
import cn.da.shuai.cool.system.model.entity.log.CoolLoginLog;
import cn.da.shuai.cool.system.service.service.ICoolLoginLogService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统访问记录
 */
@RestController
@RequestMapping("/monitor/logininfor")
@Tag(name = "登录日志控制器")
public class CoolLoginLogController {

    @Autowired
    private ICoolLoginLogService loginLogService;

    @GetMapping("/list")
    @Operation(summary = "获取登录日志列表")
    public R<List<CoolLoginLog>> list(CoolLoginLog loginLog) {
        List<CoolLoginLog> list = loginLogService.selectLoginLogList(loginLog);
        return R.ok(list);
    }

    @GetMapping("/page")
    @Operation(summary = "获取登录日志分页列表")
    public R<Page<CoolLoginLog>> page(CoolLoginLog loginLog, Page<CoolLoginLog> page) {
        Page<CoolLoginLog> list = loginLogService.selectLoginLogPage(loginLog, page);
        return R.ok(list);
    }

    @DeleteMapping("/{infoIds}")
    @Operation(summary = "删除登录日志")
    public R<Void> remove(@PathVariable Long[] infoIds) {
        loginLogService.deleteLoginLogByIds(infoIds);
        return R.ok();
    }

    @DeleteMapping("/clean")
    @Operation(summary = "清空登录日志")
    public R<Void> clean() {
        loginLogService.cleanLoginLog();
        return R.ok();
    }
}